package com.bw.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.bw.entity.OrderInfo;
import com.bw.mapper.OrderInfoMapper;
import com.bw.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Transactional
    @Override
    public void addOrder(OrderInfo orderInfo) {
        //订单编号生成，保证唯一性
        String orderNum = UUID.randomUUID().toString();
        orderInfo.setOrderNum(orderNum);
        //币种随机生成
        int currencyId = RandomUtil.randomInt(1, 8);
        orderInfo.setCurrencyId(currencyId);
        //持仓金额随机生成
        int balance = RandomUtil.randomInt(1000, 9999);
        orderInfo.setBalance(balance + "");

        orderInfoMapper.addOrder(orderInfo);
    }
}
